package com.zycfc.zsf.boot.office.pdf.util;

import com.zycfc.zsf.boot.office.pdf.generator.*;
import java.io.*;

public class PdfUtil
{
    public static byte[] genPdfToResponse(final String template, final Object dataModel) throws Exception {
        final String htmlStr = HtmlGenerator.generate(template, dataModel);
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        PdfGenerator.generatePlus(htmlStr, out);
        out.flush();
        out.close();
        return out.toByteArray();
    }
    
    public static void genPdfToServer(final String template, final Object dataModel, final String address) throws Exception {
        final String htmlStr = HtmlGenerator.generate(template, dataModel);
        final OutputStream out = new FileOutputStream(address);
        PdfGenerator.generatePlus(htmlStr, out);
        out.flush();
        out.close();
    }
}
